package com.bd.scm.module.jurisdiction.service.impl;

import com.bd.scm.dao.mapper.jurisdiction.BdSysRoleMapper;
import com.bd.scm.dao.mapper.jurisdiction.PremissionMapper;
import com.bd.scm.domain.models.jurisdiction.BdSysRole;
import com.bd.scm.module.jurisdiction.service.BdSysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**角色ServiceImpl
 * @author YH
 * @version 1.0
 * @date 2020/12/15 10:19
 */
@Service
public class BdSysRoleServiceImpl implements BdSysRoleService {

    /**
     * 角色Mapper
     */
    @Autowired
    private BdSysRoleMapper bdSysRoleMapper;

    /**
     * 权限Mapper
     */
    @Autowired
    private PremissionMapper premissionMapper;

    /**
     * 获取所有角色,角色树用
     * @return
     */
    @Override
    public List<BdSysRole> getRoleList() {
        return this.bdSysRoleMapper.getRoleList();
    }

    //增
    @Override
    public void addRole(BdSysRole role) {
        this.bdSysRoleMapper.addRole(role);
    }

    //修
    @Override
    public void updateRole(BdSysRole role) {
        this.bdSysRoleMapper.updateRole(role);
    }

    //删
    @Override
    public void deleteRole(Integer[] roleIds) {
        for(Integer roleId:roleIds){
            this.bdSysRoleMapper.deleteRole(roleId);
        }
    }

    //角色菜单功能
    @Override
    public void addRoleMenu(Integer roleId, Integer[] MenuIds) {
        this.premissionMapper.deleteRoleMenuByRoleId(roleId);
        for(int menu:MenuIds){
            this.premissionMapper.addRoleMenu(roleId,menu);
        }
    }

    @Override
    public List<Integer> getMenuByRoleId(Integer roleId) {
        List<Integer> menuIds = this.premissionMapper.getMenuByRoleId(roleId);
        return menuIds;
    }
}
